home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2514 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  59 lines

  1. Path: godel.une.edu.au!norm
  2. From: norm@godel.une.edu.au (Norman Gaywood)
  3. Newsgroups: comp.unix.osf.osf1,comp.lang.c
  4. Subject: Re: printf-problem
  5. Date: 22 Jan 1996 03:37:23 GMT
  6. Organization: University of New England, NSW, Australia
  7. Message-ID: <4dv0pj$nh2@grivel.une.edu.au>
  8. References: <4dj4g6$t9f@sunsystem5.informatik.tu-muenchen.de> <4dojc3$g2j@surz03fi.HRZ.Uni-Marburg.DE>
  9. NNTP-Posting-Host: godel.une.edu.au
  10. X-Newsreader: NN version 6.5.0 #15 (NOV)
  11.  
  12. reeh@bunsen.HRZ.Uni-Marburg.DE (Achim Reeh) writes:
  13.  
  14. >Henrik Wist (wist@lam.mw.tu-muenchen.de) wrote:
  15. >: Problem:
  16. >: long int zahl;   /* which is e.g. 10000500001 */
  17. >: printf("%d\n",zahl);      /* gives 1410565409, which is definitly wrong */
  18.  
  19. >Solution:
  20. >  printf("%ld\n",zahl);      /* gives 10000500001 */
  21. >          ^^^
  22. >%ld is the format specifier for long int output. long ints are 64 bit 
  23. >under DEC Unix and DEC C. ints (format %d) have only 32 bit.
  24.  
  25. OK, what about this one:
  26.  
  27. -------------------------------Cut----------------------
  28. cat > sprintfbug.c
  29. #include <stdio.h>
  30.  
  31. main()
  32. {
  33. static char buff[20] = "!!!!!";
  34. int width = 4;
  35. int lprecision = 0;
  36. double val = 10.0;
  37.  
  38. sprintf( buff,"%*.*f", width, lprecision, val);
  39. printf( ":%s:\n", buff );
  40. }
  41. ^D
  42. % cc -o sprintfbug sprintfbug.c 
  43. % sprintfbug 
  44. :  10!:
  45. % uname -a
  46. OSF1 metz.une.edu.au V3.2 17 alpha
  47. -------------------------------Cut----------------------
  48.  
  49. The output should be:
  50. :  10:
  51.  
  52. I found this while trying to get the sc spreadsheet working correctly.
  53. This is not a problem in OSF 2.0
  54.  
  55. --
  56. Norman Gaywood. Department of Mathematics, Statistics and Computing Science.
  57. University of New England, Armidale, NSW 2351, Australia.
  58. Internet: norm@godel.une.edu.au, phone: +61 67 732412, fax: +61 67 733312
  59.